package com.jz.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Created by Administrator on 2015/10/28.
 */
public class SystemSupport {
    public static final Logger LOGGER = LoggerFactory.getLogger(SystemSupport.class);


    public static void exit(Exception e, String message) {
        if (e == null) {
            LOGGER.error(message + " ,程序将异常退出");
        } else {
            LOGGER.error(message + " ,程序将异常退出", e);
        }
        System.exit(1);
    }

    public static InetAddress getInetAddress() {
        try {
            return InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            LOGGER.info("unknown host!");
        }
        return null;

    }

    public static String getHostIp(InetAddress netAddress) {
        if (null == netAddress) {
            return null;
        }
        String ip = netAddress.getHostAddress(); //get the ip address
        return ip;
    }

    public static String getHostName(InetAddress netAddress) {
        if (null == netAddress) {
            return null;
        }
        String name = netAddress.getHostName(); //get the host address
        return name;
    }

    public static String getLocalIp(){
        return getHostIp(getInetAddress());
    }
}
